package org.example;

//代理类 不持有源类 因为Handler持有源类 通过反射 获取信息
public class HelloImpl implements MyInterface{

    private MyInvocationHandler handler;

    public HelloImpl(MyHelloHandler myHelloHandler) {
        this.handler = myHelloHandler;
    }

    @Override
    public void func1() {
        try {
            handler.invoke(this, MyInterface.class.getMethod("func1"), null);
        }
        catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void func2() {
        try {
            handler.invoke(this, MyInterface.class.getMethod("func1"), null);
        }
        catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void func3() {
        try {
            handler.invoke(this, MyInterface.class.getMethod("func1"), null);
        }
        catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
}
